
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Feed;
import cn.edu.scau.cmi.hombio.domain.InspectionException;
import cn.edu.scau.cmi.hombio.domain.PigHouse;
import cn.edu.scau.cmi.hombio.domain.Pigsty;
import cn.edu.scau.cmi.hombio.domain.Prevention;
import cn.edu.scau.cmi.hombio.domain.TaskPigsty;
import cn.edu.scau.cmi.hombio.domain.Transfer;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class PigstyServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected PigstyService service;

	/**
	 * Instantiates a new PigstyServiceTest.
	 *
	 */
	public PigstyServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Save an existing PigHouse entity
	* 
	 */
	@Test
	public void savePigstyPigHouse() {
		// TODO: JUnit - Populate test inputs for operation: savePigstyPigHouse 
		Integer id = 0;
		PigHouse related_pighouse = new cn.edu.scau.cmi.hombio.domain.PigHouse();
		Pigsty response = null;
		response = service.savePigstyPigHouse(id, related_pighouse);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigstyPigHouse
	}

	/**
	 * Operation Unit Test
	* Delete an existing InspectionException entity
	* 
	 */
	@Test
	public void deletePigstyInspectionExceptions() {
		// TODO: JUnit - Populate test inputs for operation: deletePigstyInspectionExceptions 
		Integer pigsty_id = 0;
		Integer related_inspectionexceptions_id = 0;
		Pigsty response = null;
		response = service.deletePigstyInspectionExceptions(pigsty_id, related_inspectionexceptions_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigstyInspectionExceptions
	}

	/**
	 * Operation Unit Test
	* Save an existing Feed entity
	* 
	 */
	@Test
	public void savePigstyFeeds() {
		// TODO: JUnit - Populate test inputs for operation: savePigstyFeeds 
		Integer id_1 = 0;
		Feed related_feeds = new cn.edu.scau.cmi.hombio.domain.Feed();
		Pigsty response = null;
		response = service.savePigstyFeeds(id_1, related_feeds);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigstyFeeds
	}

	/**
	 * Operation Unit Test
	* Delete an existing Prevention entity
	* 
	 */
	@Test
	public void deletePigstyPreventions() {
		// TODO: JUnit - Populate test inputs for operation: deletePigstyPreventions 
		Integer pigsty_id_1 = 0;
		Integer related_preventions_id = 0;
		Pigsty response = null;
		response = service.deletePigstyPreventions(pigsty_id_1, related_preventions_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigstyPreventions
	}

	/**
	 * Operation Unit Test
	* Delete an existing Feed entity
	* 
	 */
	@Test
	public void deletePigstyFeeds() {
		// TODO: JUnit - Populate test inputs for operation: deletePigstyFeeds 
		Integer pigsty_id_2 = 0;
		Integer related_feeds_id = 0;
		Pigsty response = null;
		response = service.deletePigstyFeeds(pigsty_id_2, related_feeds_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigstyFeeds
	}

	/**
	 * Operation Unit Test
	* Save an existing TaskPigsty entity
	* 
	 */
	@Test
	public void savePigstyTaskPigsties() {
		// TODO: JUnit - Populate test inputs for operation: savePigstyTaskPigsties 
		Integer id_2 = 0;
		TaskPigsty related_taskpigsties = new cn.edu.scau.cmi.hombio.domain.TaskPigsty();
		Pigsty response = null;
		response = service.savePigstyTaskPigsties(id_2, related_taskpigsties);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigstyTaskPigsties
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findPigstyByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findPigstyByPrimaryKey 
		Integer id_3 = 0;
		Pigsty response = null;
		response = service.findPigstyByPrimaryKey(id_3);
		// TODO: JUnit - Add assertions to test outputs of operation: findPigstyByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Delete an existing TaskPigsty entity
	* 
	 */
	@Test
	public void deletePigstyTaskPigsties() {
		// TODO: JUnit - Populate test inputs for operation: deletePigstyTaskPigsties 
		Integer pigsty_id_3 = 0;
		Integer related_taskpigsties_id = 0;
		Pigsty response = null;
		response = service.deletePigstyTaskPigsties(pigsty_id_3, related_taskpigsties_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigstyTaskPigsties
	}

	/**
	 * Operation Unit Test
	* Delete an existing PigHouse entity
	* 
	 */
	@Test
	public void deletePigstyPigHouse() {
		// TODO: JUnit - Populate test inputs for operation: deletePigstyPigHouse 
		Integer pigsty_id_4 = 0;
		Integer related_pighouse_id = 0;
		Pigsty response = null;
		response = service.deletePigstyPigHouse(pigsty_id_4, related_pighouse_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigstyPigHouse
	}

	/**
	 * Operation Unit Test
	* Load an existing Pigsty entity
	* 
	 */
	@Test
	public void loadPigstys() {
		Set<Pigsty> response = null;
		response = service.loadPigstys();
		// TODO: JUnit - Add assertions to test outputs of operation: loadPigstys
	}

	/**
	 * Operation Unit Test
	* Save an existing Pigsty entity
	* 
	 */
	@Test
	public void savePigsty() {
		// TODO: JUnit - Populate test inputs for operation: savePigsty 
		Pigsty pigsty = new cn.edu.scau.cmi.hombio.domain.Pigsty();
		service.savePigsty(pigsty);
	}

	/**
	 * Operation Unit Test
	* Save an existing Prevention entity
	* 
	 */
	@Test
	public void savePigstyPreventions() {
		// TODO: JUnit - Populate test inputs for operation: savePigstyPreventions 
		Integer id_4 = 0;
		Prevention related_preventions = new cn.edu.scau.cmi.hombio.domain.Prevention();
		Pigsty response = null;
		response = service.savePigstyPreventions(id_4, related_preventions);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigstyPreventions
	}

	/**
	 * Operation Unit Test
	* Delete an existing Pigsty entity
	* 
	 */
	@Test
	public void deletePigsty() {
		// TODO: JUnit - Populate test inputs for operation: deletePigsty 
		Pigsty pigsty_1 = new cn.edu.scau.cmi.hombio.domain.Pigsty();
		service.deletePigsty(pigsty_1);
	}

	/**
	 * Operation Unit Test
	* Return all Pigsty entity
	* 
	 */
	@Test
	public void findAllPigstys() {
		// TODO: JUnit - Populate test inputs for operation: findAllPigstys 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Pigsty> response = null;
		response = service.findAllPigstys(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllPigstys
	}

	/**
	 * Operation Unit Test
	* Save an existing Transfer entity
	* 
	 */
	@Test
	public void savePigstyTransfers() {
		// TODO: JUnit - Populate test inputs for operation: savePigstyTransfers 
		Integer id_5 = 0;
		Transfer related_transfers = new cn.edu.scau.cmi.hombio.domain.Transfer();
		Pigsty response = null;
		response = service.savePigstyTransfers(id_5, related_transfers);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigstyTransfers
	}

	/**
	 * Operation Unit Test
	* Return a count of all Pigsty entity
	* 
	 */
	@Test
	public void countPigstys() {
		Integer response = null;
		response = service.countPigstys();
		// TODO: JUnit - Add assertions to test outputs of operation: countPigstys
	}

	/**
	 * Operation Unit Test
	* Delete an existing Transfer entity
	* 
	 */
	@Test
	public void deletePigstyTransfers() {
		// TODO: JUnit - Populate test inputs for operation: deletePigstyTransfers 
		Integer pigsty_id_5 = 0;
		Integer related_transfers_id = 0;
		Pigsty response = null;
		response = service.deletePigstyTransfers(pigsty_id_5, related_transfers_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePigstyTransfers
	}

	/**
	 * Operation Unit Test
	* Save an existing InspectionException entity
	* 
	 */
	@Test
	public void savePigstyInspectionExceptions() {
		// TODO: JUnit - Populate test inputs for operation: savePigstyInspectionExceptions 
		Integer id_6 = 0;
		InspectionException related_inspectionexceptions = new cn.edu.scau.cmi.hombio.domain.InspectionException();
		Pigsty response = null;
		response = service.savePigstyInspectionExceptions(id_6, related_inspectionexceptions);
		// TODO: JUnit - Add assertions to test outputs of operation: savePigstyInspectionExceptions
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
